<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Listens for a connection on a socket</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.socket-listen" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">socket_listen</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.1.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">socket_listen</span> &mdash; <span class="dc-title">Listens for a connection on a socket</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.socket-listen-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>socket_listen</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$socket</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$backlog</code><span class="initializer"> = 0</span></span>
  ] ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   After the socket <code class="parameter">socket</code> has been created
   using <span class="function"><a href="socket_create.html" class="function">socket_create()</a></span> and bound to a name with
   <span class="function"><a href="socket_bind.html" class="function">socket_bind()</a></span>, it may be told to listen for incoming
   connections on <code class="parameter">socket</code>.
  </p>
  <p class="para">
   <span class="function"><strong>socket_listen()</strong></span> is applicable only to sockets of
   type <strong><code>SOCK_STREAM</code></strong> or
   <strong><code>SOCK_SEQPACKET</code></strong>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.socket-listen-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">socket</code></dt>

     <dd>

      <p class="para">
       A valid socket resource created with <span class="function"><a href="socket_create.html" class="function">socket_create()</a></span>
       or <span class="function"><a href="socket_addrinfo_bind.html" class="function">socket_addrinfo_bind()</a></span>
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">backlog</code></dt>

     <dd>

      <p class="para">
       A maximum of <code class="parameter">backlog</code> incoming connections will be
       queued for processing. If a connection request arrives with the queue
       full the client may receive an error with an indication of
       <em>ECONNREFUSED</em>, or, if the underlying protocol supports
       retransmission, the request may be ignored so that retries may succeed.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        The maximum number passed to the <code class="parameter">backlog</code>
        parameter highly depends on the underlying platform. On Linux, it is
        silently truncated to <strong><code>SOMAXCONN</code></strong>. On win32, if
        passed <strong><code>SOMAXCONN</code></strong>, the underlying service provider
        responsible for the socket will set the backlog to a maximum
        <em class="emphasis">reasonable</em> value. There is no standard provision to
        find out the actual backlog value on this platform.
       </p>
      </p></blockquote>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.socket-listen-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。 The error code can be retrieved with
   <span class="function"><a href="socket_last_error.html" class="function">socket_last_error()</a></span>. This code may be passed to
   <span class="function"><a href="socket_strerror.html" class="function">socket_strerror()</a></span> to get a textual explanation of the
   error.
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.socket-listen-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="socket_accept.html" class="function" rel="rdfs-seeAlso">socket_accept()</a> - Accepts a connection on a socket</span></li>
    <li class="member"><span class="function"><a href="socket_bind.html" class="function" rel="rdfs-seeAlso">socket_bind()</a> - 给套接字绑定名字</span></li>
    <li class="member"><span class="function"><a href="socket_connect.html" class="function" rel="rdfs-seeAlso">socket_connect()</a> - 开启一个套接字连接</span></li>
    <li class="member"><span class="function"><a href="socket_create.html" class="function" rel="rdfs-seeAlso">socket_create()</a> - 创建一个套接字（通讯节点）</span></li>
    <li class="member"><span class="function"><a href="socket_strerror.html" class="function" rel="rdfs-seeAlso">socket_strerror()</a> - Return a string describing a socket error</span></li>
    <li class="member"><span class="function"><a href="socket_addrinfo_bind.html" class="function" rel="rdfs-seeAlso">socket_addrinfo_bind()</a> - Create and bind to a socket from a given addrinfo</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>